Skip to content

Updated RegexFilter implementtation with changes from 2.x branch merge to main [3.x] (#3086) #3513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

JWT007
Copy link
Contributor

@JWT007 JWT007 commented Mar 2, 2025

Fixes #3086

  • add RegexFilter(Builder) private constructor
  • add RegexFilter#getPattern()
  • add RegexFilter#getRegex()
  • add RegexFilter#isUseRawMessage()
  • add RegexFiltter changes from Deprecate Message#getFormat() #2773 from 2.x branch that were only partially merged to main
  • add JVerify nullability annotations
  • add protected AbstractFilter(Builder) constructor
  • removed deprecated API
  • updated all RegexFilter javadoc
  • updated RegexFilterTest
  • updated AbstractFilterableTest - fixed JUnit5 warnings
  • updated AbstractFilterTestt

NOTE: cherry-picking changes directly from 2.x branch not possible due to missing APIs, changed 3.x Plugin design/imports, etc.

JWT007 added 12 commits March 2, 2025 21:45
+ made AbstractFiltter.AbstractFilterBuilder onMatch/onMismatch fields protected
+ added AbstractFilter(AbstractFilterBuilder) constructor
+ added RegexFilter.Builder implementation
+ added RegexFilter(Builder) constructor
+ moved RegexFilter Pattern compile into constructor
+ added fields to persist configuration propertties + getters (regexExpression, patternFlags)
+ changed private constructor to accept builder as argument
+ renamed private method 'targetMessageTest' to more approprriate 'getMessageTextByType'
+ added Javadoc
+ grouped deprecations
+ added validation checks to RegexFilter
+ added JVerify nullability annotations to RegexFilter
+ updated javadoc
+ replaced deprecated usages of CompositeFilter#getFilters with CompositeFilter#getFiltersArray in AbstractFilterableTest
@JWT007 JWT007 added bug Incorrect, unexpected, or unintended behavior of existing code java Pull requests that update Java code tests Pull requests or issues related to tests configuration Affects the configuration system in a general way labels Mar 2, 2025
@JWT007 JWT007 requested a review from ppkarwasz March 2, 2025 22:58
@JWT007 JWT007 self-assigned this Mar 2, 2025
@JWT007 JWT007 linked an issue Mar 2, 2025 that may be closed by this pull request
Copy link

github-actions bot commented Mar 2, 2025

Job Requested goals Build Tool Version Build Outcome Build Scan®
build-windows-latest clean install 3.9.8 Build Scan PUBLISHED
Generated by gradle/develocity-actions

@ppkarwasz ppkarwasz added this to the 2.25.0 milestone Apr 13, 2025
Copy link
Contributor

@ppkarwasz ppkarwasz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JWT007,

Sorry for reviewing it so late. The PR looks very nice, I would just address the remarks below:

@PluginBuilderAttribute(ATTR_ON_MATCH)
private Result onMatch = Result.NEUTRAL;
protected Result onMatch = Result.NEUTRAL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a getter and a setter. Making this protected is not needed.

@PluginBuilderAttribute(ATTR_ON_MISMATCH)
private Result onMismatch = Result.DENY;
protected Result onMismatch = Result.DENY;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a getter and a setter. Making this protected is not needed.

Comment on lines +86 to 92
/**
* Returns the compiled regular-expression pattern.
* @return the pattern (will never be {@code null}
*/
public Pattern getPattern() {
return this.pattern;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there is already a getRegex method below, I think this method can be removed.

Comment on lines 257 to -142
@PluginFactory
public static RegexFilter createFilter(
// @formatter:off
@PluginAttribute final String regex,
@PluginElement final String[] patternFlags,
@PluginAttribute final Boolean useRawMsg,
@PluginAttribute final Result onMatch,
@PluginAttribute final Result onMismatch)
// @formatter:on
throws IllegalArgumentException, IllegalAccessException {
if (regex == null) {
LOGGER.error("A regular expression must be provided for RegexFilter");
return null;
}
return new RegexFilter(useRawMsg, Pattern.compile(regex, toPatternFlags(patternFlags)), onMatch, onMismatch);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For backward compatibility, we can not remove this method, but we can:

  • Remove the @PluginFactory annotation.
  • Deprecated it.
  • Rewrite it in terms of builder calls.

Comment on lines +258 to 260
public static Builder newBuilder() {
return new Builder();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A plugin builder factory must be annotated with @PluginBuilderFactory instead of @PluginFactory.

@ppkarwasz ppkarwasz modified the milestones: 2.25.0, 2.25.1 May 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect, unexpected, or unintended behavior of existing code configuration Affects the configuration system in a general way java Pull requests that update Java code tests Pull requests or issues related to tests
Projects
Status: To triage
Development

Successfully merging this pull request may close these issues.

Fix RegexFilter pattern flags
2 participants